package com.stylefeng.guns.modular.netcar.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.modular.netcar.dao.OrderLineCommentMapper;
import com.stylefeng.guns.modular.netcar.model.OrderLineComment;
import com.stylefeng.guns.modular.netcar.service.IOrderLineCommentService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 线路审核意见表 Service 实现 
 * @author 张亚林
 * @Date 2018-11-30 14:56
 */
@Service
public class OrderLineCommentServiceImpl extends ServiceImpl<OrderLineCommentMapper,OrderLineComment> implements IOrderLineCommentService {

    @Resource
    private OrderLineCommentMapper orderLineCommentMapper;

    /**
     * 删除线路审核意见表
     * @param orderLineComment
     * @return     
     */
    @Transactional
    public int deleteOrderLineComment(OrderLineComment orderLineComment,String token)throws Exception{
        if(orderLineComment==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.orderLineCommentMapper.deleteOrderLineComment(orderLineComment);
    }
    /**
     * 批量删除线路审核意见表
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchOrderLineComment(String[] ids,String token)throws Exception{
        return this.orderLineCommentMapper.deleteBatchOrderLineComment(ids);
    }
    /**
     * 查询线路审核意见表列表
     * @param orderLineComment 线路审核意见表对象
     * @return
     */
    public List<OrderLineComment> selectListOrderLineComment(OrderLineComment orderLineComment,String token)throws Exception{
        return  this.orderLineCommentMapper.selectListOrderLineComment(orderLineComment);
    }
    /**
	 * 分页查询线路审核意见表列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListOrderLineComment(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(orderLineCommentMapper.selectListOrderLineComment(page,(OrderLineComment)pager.getObj()));
        List<OrderLineComment> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderLineComment 线路审核意见表对象
     * @return 
     */
    public  List<OrderLineComment> selectListOrderLineCommentForUpdate(OrderLineComment orderLineComment)throws Exception{
        return  this.orderLineCommentMapper.selectListOrderLineCommentForUpdate(orderLineComment);
    }
    /**
     * 通过主键id查询的线路审核意见表列表
     * @param id 主键id
     * @return     
     */
    public  OrderLineComment findOrderLineCommentById(String id,String token)throws Exception{
        return  this.orderLineCommentMapper.findOrderLineCommentById(id);
    }

    /**
     * 新增线路审核意见表数据
     * @param orderLineComment  线路审核意见表对象
     * @return
     */
    @Transactional
    public int insertOrderLineComment(OrderLineComment orderLineComment,String token) throws Exception { 
        if(orderLineComment!=null && (orderLineComment.getOlcId()==null || orderLineComment.getOlcId().trim().length()<10)){
            orderLineComment.setOlcId(IdWorker.get32UUID());
        }  
        return this.orderLineCommentMapper.insertOrderLineComment(orderLineComment);
    }
    
    /**
     * 更新线路审核意见表数据
     * @param orderLineComment 线路审核意见表对象
     * @return     
     */
    @Transactional
    public int updateOrderLineComment(OrderLineComment orderLineComment,String token) throws Exception {     	
        return  this.orderLineCommentMapper.updateOrderLineComment(orderLineComment);
    }    
    /**
     * 查询线路审核意见表返回key-Value属性
     * @param orderLineComment 系统操作对象
     * @return     
     */
    public List<CommonKeyValue> optionsOrderLineComment(OrderLineComment orderLineComment,String token) throws Exception {
        List<OrderLineComment> listOrderLineComment=this.orderLineCommentMapper.selectListOrderLineComment(orderLineComment);
        List<CommonKeyValue> listOptions=new ArrayList<CommonKeyValue>();
        for(OrderLineComment item:listOrderLineComment){
            CommonKeyValue opts=new CommonKeyValue();
            opts.setId(item.getOlcId());
            opts.setValue(item.getOlId());
            listOptions.add(opts);
        }
        return listOptions;
    }
}
